package com.tutu.controller.activity;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;

import com.tutu.R;
import com.tutu.controller.adapter.InviteAdapter;
import com.tutu.model.Model;
import com.tutu.model.bean.InvitationInfo;

import java.util.List;


/**
 * @author 谢辉
 * 邀请信息列表页面
 */
public class InviteActivity extends Activity {

    private ListView lv_invite;
    private InviteAdapter mInviteAdapter;
    private InviteAdapter.OnInviteListener mOnInviteListener = new InviteAdapter.OnInviteListener() {
        @Override
        public void onAccept(InvitationInfo invitationInfo) {

        }

        @Override
        public void onReject(InvitationInfo invitationInfo) {

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_invite);

        initView();
        initData();
    }

    private void initData() {
        // 初始化listview
        mInviteAdapter = new InviteAdapter(this, mOnInviteListener);
        lv_invite.setAdapter(mInviteAdapter);

        // 刷新方法
        refresh();

    }

    private void refresh() {
        // 获取数据库中的邀请信息
        List<InvitationInfo> invitationInfos = Model.getInstance().getDbManager().getInviteTableDao().getInvitationInfos();
        // 刷新适配器
        mInviteAdapter.refresh(invitationInfos);
    }

    private void initView() {
        lv_invite = (ListView) findViewById(R.id.lv_invite);

    }
}
